package com.hisense.hiioc.hismartplate.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;

/**
 * @Author: almo
 * @Date: 2018/12/27 上午10:17
 * @Version 1.0
 */
@Configuration
public class WebResourceConfig extends WebMvcConfigurerAdapter {
    @Value("${apkFilePath:/usr/local/downloads/}")
    private String apkFilePath;
    @Value("${snapFilePath:/usr/local/downloads/snap/}")
    private String snapFilePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/apkFile/**").addResourceLocations("file:"+apkFilePath);
        registry.addResourceHandler("/resFile/**").addResourceLocations("file:"+apkFilePath);
        registry.addResourceHandler("/snapFile/**").addResourceLocations("file:"+snapFilePath); //ToDo 需要配置为服务器本地路径
        super.addResourceHandlers(registry);
    }

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize("350MB");
        factory.setMaxRequestSize("102400KB");
        return factory.createMultipartConfig();
    }
}
